﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SlamDunk.MES.Domain.Entities.ConfigurationContext;

namespace SlamDunk.MES.Repository.EntityConfigurations.ConfigurationContext
{
    /// <summary>
    /// 硬件实体映射配置
    /// </summary>
    public class HardwareConfig : IEntityTypeConfiguration<Hardware>
    {
        /// <summary>
        /// 配置
        /// </summary>
        public void Configure(EntityTypeBuilder<Hardware> builder)
        {
            //配置属性
            builder.HasKey(hardware => hardware.Id).IsClustered(false);
            builder.HasOne(hardware => hardware.Connection).WithOne(conn => conn.Hardware).HasForeignKey<HardwareConnection>(conn => conn.HardwareId).IsRequired().OnDelete(DeleteBehavior.Cascade);

            //配置索引
            builder.HasIndex(hardware => hardware.AddedTime).IsUnique(false).IsClustered();
        }
    }
}
